#pragma once
#include "Texture.h"
#include "Input.h"
#include "OSD.h"
#include "EngineData.h"
#include "Player.h"
#include "Enemy.h"
#include "DX9Engine.h"
#include "Squad.h"
#include "Boss.h"

struct minions {
	float spawnTime;
	bool moving;
	V2DI pos;
	V2DF velocity;
};

class Level
{
private:
	
	//Objects
	Texture tex;
	Timer time;
	minions * m;
	Player p;
	PhysicSystem m_PhysicSystem;
	DX9Engine* pEngine;
	Input* pInput;

	//FOR DEBUG ONLY
	OSD o;
	bool bgOn;
	
	//Level variables
	float levelNow;
	int levelNum;
	int bossState;
	int numMinions;

	int t_sizeBulletList;
	int t_sizeSquadList;
	int t_sizeEnemyBulletList;

	int minionState;
	bool bossSpawn;
	//Physic Object Lists
	LinkedList<Bullet *> playerBulletList;
	LinkedList<Bullet *> enemyBulletList;
	LinkedList<Squad *> m_squadList;

	bool gameover;

	Boss *m_Boss;

public:
	Level(void);
	void Init();
	void setBoss(); // set boss info
	void startLevel(); // set level info with num of minions to load
	void endLevel(); //release level info
	void setBG(LPCWSTR file); //set background image
	void setMinions(int num,  int x, int y, int dx, int dy,float scale, float rot,float speed, int dur, LPCWSTR file, LPCWSTR bulletfile); //set num of minions at x,y
	
	
	void contact(); //all contacts go here
	bool onScreen(PhysicObject p); // simple check if a physic object is on the screen + buffer
	void fireBullets(); //bullets go here
	void movementControl();

	void render(); //renders the whole level
	void update(float dt); //updates the whole level
	void updateBullets(); //update bullets
	void updateMinions(); //update minions
	void updateBG(float dt); //update background
	void renderMinions(); //render minions
	void updateBoss(float dt); //update boss
	void renderBoss(); // render boss
	~Level(void);
	void Release();

	float getLevelTime() { return levelNow; };
	enum levelState {WAIT,START,PLAYING,GAMEOVER} state; //state machine for level

	//create bullet function
	void createBullet(V2DF pos, V2DF vel, int scale, float rot, float speed,  LPCWSTR file);

	void playerDie();
	//checks for contact between player bullet and enemy bullet
	void contactBulletEnemy(LinkedList<Bullet *> b,LinkedList<Enemy *>e);
	//destroys a bullet and releases it
	void destroyBullet(LinkedList<Bullet *> b, int index);
	//destroys an enemy and releases it
	void destroyEnemy(LinkedList<Enemy *> e, int index);
	//contact between player and enemy
	void contactPlayerEnemy(Player player, LinkedList<Enemy *>e);
	//move minion index[s-e], velocity(dx,dy)
	void moveMinion(Squad *a_squad,int x, int y, float dx, float dy);

	//updates enemies
	void updateEnemy();

	void levelOne(float dt);
	
	void levelTwo(float dt);

	enum level {ONE = 1, TWO, THREE} lvl;

	bool gameOver();
};

